package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.annotation.RequiresPermissionsDesc;
import com.qf.pojo.DtsAccountTrace;
import com.qf.pojo.DtsUser;
import com.qf.service.DtsAccountTraceService;
import com.qf.service.DtsUserService;
import com.qf.util.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Zwnan
 */

@RestController
@RequestMapping("/admin/brokerage")
@CrossOrigin
public class BrokerageController {

    @Autowired
    DtsAccountTraceService dtsAccountTraceService;
    @RequiresPermissionsDesc(menu = {"用户管理","佣金管理"},button = "审批")
    @RequiresPermissions("admin:brokerage:list")
    @GetMapping("/list")
    public Object brokerageList(@RequestParam(defaultValue = "1") Integer page
            ,@RequestParam(defaultValue = "20") Integer limit
            ,@RequestParam(defaultValue = "add_time") String sort
            ,@RequestParam(defaultValue = "desc") String order){
        IPage<DtsAccountTrace> iPage = dtsAccountTraceService.selectByPage(page,limit,sort,order);
        long total = iPage.getTotal();
        List<DtsAccountTrace> records = iPage.getRecords();

        Map map = new HashMap();
        map.put("total", total);
        map.put("traceList", records);
        return ResponseUtil.ok(map);
    }

    @PostMapping("/approve")
    public Object approve(@RequestBody DtsAccountTrace dtsAccountTrace){
        dtsAccountTraceService.approve(dtsAccountTrace);
        return ResponseUtil.ok();
    }

}
